<?php

class CartRepository {

    var $db;

    function CartRepository() {
        global $SERVER, $DATABASE, $USERNAME, $PASSWORD;
        $this->db = new Connection($SERVER, $DATABASE, $USERNAME, $PASSWORD);
    }

    public function UpdateCart($id, $quan) {
        if (isset($_SESSION['cart'][$id])) {
            $_SESSION['cart'][$id] = $quan;
            return TRUE;
        } else {
            return FALSE;
        }
    }

    public function GetCartCount(){
        $count = 0;
        foreach ($_SESSION['cart'] as $key => $value) {
            $count++;
        }
        return $count;
    }

    public function DeleteItem($id){
        if(isset($_SESSION['cart'][$id])){
            unset ($_SESSION['cart'][$id]);
        }
    }
}

?>
